<?php
class SiteController extends Controller {
   
    private $_model;
    public $defaultAction='listing';
    
    /*
    public function accessRules() {
        return array(
            array('allow', // allow authenticated users to access all actions
                'users' => array('?'), //authenticated user
            ),
            array('deny'),	//commond practice: place this at the end
        );
    }*/

    public function init() {
        parent::init();
        $this->breadcrumbs = array(
            Lang::t('merchant.page.breadcrumbs') => Yii::app()->createUrl('account'),
        );
    }
    
    public function actionIndex() {
        $this->render('index');
    }
    
    public function actionListing(){
        $model=new Account('userSearch');
        $article=Article::model()->byType(Option::ARTICLE_TYPE_ACCOUNT_DIRECTORY)->published()->find();
        $this->render('listing',array(
            'account'=>$model,
            'article'=>$article,
            'dataProvider'=>$model->userSearch(),
        ));
    }
    
    public function actionView($id){
        $data=$this->loadModel($id);
        $data->scenario='userView';
        $data->updateViewCounter();
        $this->render('view',array(
            'account'=>$data,
        ));
    }
    
    public function loadModel($id=null){
        if($this->_model===null){
            if(empty($id)) HttpStatus::code(404);
            
            $this->_model=Account::model()->published()->findByPk((int)$id);
            if(empty($this->_model)) HttpStatus::code(404);
        }
        return $this->_model;
    }
}